﻿using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
	#endregion
	public partial class HomeController: BaseController
	{
		public ActionResult Index()
		{
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_INDEX
            };
            return View(CreateViewModel(data));
		}

        public ActionResult GioiThieu()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_GIOITHIEU
            };
            return View(CreateViewModel(data));
        }

        public ActionResult LoiIchKhachHang()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_GIOITHIEU
            };
            return View(CreateViewModel(data));
        }

        public ActionResult ThietKeWeb()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_THIETKEWEB
            };
            return View(CreateViewModel(data));
        }

        public ActionResult ChiTietDanhMucWeb(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_CHITIETDANHMUCWEB,
                IntID = id,
                IDDanhMucWeb = id
            };
            return View(CreateViewModel(data));
        }

        public ActionResult PhanMemQuanLy()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_PHANMEMQUANLY
            };
            return View(CreateViewModel(data));
        }

        public ActionResult ChiTietPhanMemQuanLy(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_CHITIETPHANMEMQUANLY,
                IntID = id
            };
            return View(CreateViewModel(data));
        }

        public ActionResult GoiDichVu(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_GOIDICHVU,
                IntID = id
            };
            return View(CreateViewModel(data));
        }

        public ActionResult KhachHang()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_KHACHHANG
            };
            return View(CreateViewModel(data));
        }

        public ActionResult TinTuc(int idloaitintuc, int page = 1)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_TINTUC,
                IDLoaiTinTuc = idloaitintuc,
                CurrentPage = page
            };
            return View(CreateViewModel(data));
        }

        public ActionResult ChiTietTinTuc(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_CHITIETTINTUC,
                IntID = id
            };
            return View(CreateViewModel(data));
        }

        public ActionResult Album(int idloaivideo)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_ALBUM,
                IDLoaiVideo = idloaivideo
            };
            return View(CreateViewModel(data));
        }

        public ActionResult Video(int idalbum, int page = 1)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_VIDEO,
                IDAlbum = idalbum,
                IntID = idalbum,
                CurrentPage = page
            };
            return View(CreateViewModel(data));
        }

        public ActionResult ShowVideo(int idalbum, int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_SHOWVIDEO,
                IntID = id,
                IDAlbum = idalbum
            };
            return View("Video", CreateViewModel(data));
        }

        public ActionResult KhachHangLamPhanMem(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_KHACHHANGLAMPHANMEM,
                IntID = id
            };
            return View(CreateViewModel(data));
        }

        public ActionResult LienHe()
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_LIENHE
            };
            return View(CreateViewModel(data));
        }

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult InsertLienHe(FormCollection forms)
        {
            string hoten = forms.GetValues("HopThu_HoTen")[0];
            string email = forms.GetValues("HopThu_Email")[0];
            string tieude = forms.GetValues("HopThu_TieuDe")[0];
            string noidung = forms.GetValues("HopThu_NoiDung")[0];

            var newItem = new HopThu
            {
                EmailNguoiHoi = email,
                TieuDe = tieude,
                NoiDung = noidung,
                NgayHoi = DateTime.Now,
                DaPhanHoi = false,
                HoTen = hoten
            };
            var result = _repHopThu.Insert(newItem);
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_LIENHE
            };
            ViewData["HoiDap"] = result ? "Thư của bạn đã được gửi đi, sau khi xem xét chúng tôi sẽ gửi phản hồi cho bạn!" : "Thư của bạn chưa được gửi đi, có lỗi sảy ra trong quá trình gửi câu hỏi.";
            return View("LienHe", CreateViewModel(data));
        }

        public ActionResult ChuongTrinhKhuyenMai(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.HOME_CHUONGTRINHKHUYEMAI,
                IntID = id
            };
            return View(CreateViewModel(data));
        }
	}
}